package com.bank.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bank.dao.BookkeepingDao;
import com.bank.dao.TransAccountListDao;
import com.bank.entity.Account;
import com.bank.excption.CommonException;
import com.bank.util.AccountingParam;

@Service("HandAccountService")
public class HandAccountServiceimpl implements HandAccountService {

	Logger logger = Logger.getLogger(HandAccountServiceimpl.class);
	
	@Autowired
	BookkeepingDao  bookkeepingDao;
	
	@Autowired
	BookkeepingCommon bookkeepingCommon;
	
	@Autowired
	TransAccountListDao  transAccountListDao;
	/***
	 * 存款
	 * @return
	 * **/
	public void deposit(Map<String, Object> params) throws CommonException{
		
		Account account =(Account) params.get("account");
		String amountStr = (String)params.get("amount");
		Double amountDou = Double.parseDouble(amountStr);
		List<AccountingParam> accountParamList = new ArrayList<AccountingParam>();
		AccountingParam accountingParamC = new AccountingParam();//贷方
		accountingParamC.setCurrency("01");
		accountingParamC.setAccount(account);
		accountingParamC.setTranAmouny(amountDou);
		AccountingParam accountingParamD = new AccountingParam();//借方
		accountingParamD.setCurrency("01"); //01   人民币
		accountingParamD.setAccounting_ori((String)params.get("trans_ori"));//帐务机构
		accountingParamD.setTranAmouny(amountDou);
		accountParamList.add(accountingParamD);
		accountParamList.add(accountingParamC);
		bookkeepingCommon.common(accountParamList, params);//记账
	}

	public void withrawal(Map<String, Object> params) throws CommonException {
		// TODO Auto-generated method stub
		Account account =(Account) params.get("account");
		String amountStr = (String)params.get("amount");
		Double amountDou = Double.parseDouble(amountStr);
		List<AccountingParam> accountParamList = new ArrayList<AccountingParam>();
		AccountingParam accountingParamD = new AccountingParam();//借方
		accountingParamD.setCurrency("01");
		accountingParamD.setAccount(account);
		accountingParamD.setTranAmouny(amountDou);
		AccountingParam accountingParamC = new AccountingParam();//贷方
		accountingParamC.setCurrency("01"); //01   人民币
		accountingParamC.setAccounting_ori((String)params.get("trans_ori"));//帐务机构
		accountingParamC.setTranAmouny(amountDou);
		accountParamList.add(accountingParamD);
		accountParamList.add(accountingParamC);
		bookkeepingCommon.common(accountParamList, params);//记账
	}

	public List<Object> getAccountDetailList(Map<String, Object> params) {
		
		// TODO Auto-generated method stub
		return transAccountListDao.getAccountDetailList(params);
	}

	public Integer getAccounDetailtListCount(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return transAccountListDao.getAccounDetailtListCount(params);
	}
	
}
